<template>
  <!-- 用户组织关系对象，组织成员 首页 -->
  <el-dialog
    v-el-drag-dialog
    :title="crud.status.title"
    :visible.sync="crud.status.info > 0"
    :before-close="crud.closeInfo"
  >
    <div class="info_detail_dialog__body">
      <el-card v-loading="crud.infoLoading" class="box-card" shadow="hover">
        <el-tabs>
          <el-tab-pane label="成员信息">
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">详情ID: </div><div class="info_detail_value">{{ info.id }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">用户名: </div><div class="info_detail_value">{{ info.username || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">姓名: </div><div class="info_detail_value">{{ info.memberName || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">所属组织: </div><div class="info_detail_value">{{ depName|| '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">岗位名称: </div><div class="info_detail_value">{{ info.stationName || '-' }}</div></el-col>
              <!-- 智能推断为字典类型, 字典类型为 dict.sys_user_dep_position_code -->
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">岗位职级 </div><div class="info_detail_value">{{ dict.label.sys_user_dep_position_code[info.positionCode] || '未知字典码:'+info.positionCode }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">用户员工编号: </div><div class="info_detail_value">{{ info.userEmployeeNum || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">联系地址: </div><div class="info_detail_value">{{ info.linkAddress || '-' }}</div></el-col>
              <!-- 数据权限 1 查看个人数据  2 查看本部门数据 4.当前组织以及下级数据 8:查看指定部门数据 -->
              <!-- 智能推断为字典类型, 字典类型为 dict.sys_user_dep_data_level -->
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">数据权限: </div><div class="info_detail_value">{{ $parent.getSysUserDepDataLevelLabel(info.dataLevel) }}</div></el-col>
              <!-- 状态值，字典取值 -->
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">状态: </div><div class="info_detail_value">{{ $parent.getMemberStatuslabel(info.status) }}</div></el-col>

              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">创建时间:</div><div class="info_detail_value">{{ info.createTime || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">创建人:</div><div class="info_detail_value">{{ info.createUserName || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">最后一次修改时间:</div><div class="info_detail_value">{{ info.updateTime || '-' }}</div></el-col>
              <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">最后一次修改人:</div><div class="info_detail_value">{{ info.updateUserName || '-' }}</div></el-col>
              <!-- <el-col :xs="24" :sm="12" :md="8"><div class="info_detail_name">是否被删除数据:</div><div class="info_detail_value">{{ info.isDel?'否':'是' }}</div></el-col> -->

            </el-row>
          </el-tab-pane>
          <el-tab-pane label="用户信息">
            <user-info :user-info="userModel" />
          </el-tab-pane>
          <el-tab-pane label="角色信息" name="userRole">
            <user-role :user-roles="userRoles" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </el-dialog>
</template>

<script>
import elDragDialog from '@/directive/el-drag-dialog'
import CRUD, { info } from '@crud/crud'
import defaultModel from './model'
import userInfo from './userInfo'
import UserRole from '@/views/sys/User/UserRole/info'
import { info as getUserInfo } from '@/api/sys/User'
import { defaultInfo as userModel } from '@/views/sys/User/info'
import { getRolesByUserAndDep } from '@/api/sys/UserRole'
// 用户组织关系对象，组织成员 - model
const defaultInfo = {
  ...defaultModel,
  createTime: null,
  createUserName: null,
  updateTime: null,
  updateUserName: null,
  // _parentInfo: {},
  isDel: 0

}
export default {
  directives: { elDragDialog },
  dicts: [
    'sys_user_dep_position_code'
  ], // 字典
  components: {
    userInfo,
    UserRole
  },
  mixins: [info(defaultInfo)],
  props: {
    depName: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      userModel: userModel,
      userRoles: []
    }
  },
  mounted() {
  },
  methods: {
    [CRUD.HOOK.afterDoInfo](crud, info) {
      getUserInfo(info.userId).then(res => {
        this.userModel = res.data
      })
      const params = {
        userId: info.userId,
        depId: info.depId
      }
      getRolesByUserAndDep(params).then(res => {
        if (res && res.data) {
          this.userRoles = res.data
        } else {
          this.userRoles = []
        }
      })
      return true
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
